package trlygjj.tanruiliyigenjinjin.web.controller;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import trlygjj.tanruiliyigenjinjin.domain.ProfessionalStuent;
import trlygjj.tanruiliyigenjinjin.domain.Tuition;
import trlygjj.tanruiliyigenjinjin.page.PageResult;
import trlygjj.tanruiliyigenjinjin.query.QueryObject;
import trlygjj.tanruiliyigenjinjin.service.ITuitionService;
import trlygjj.tanruiliyigenjinjin.util.JsonResult;
import trlygjj.tanruiliyigenjinjin.util.PermissionName;

import java.util.List;

/**
 * 学员缴费
 */
@Controller
@RequestMapping("tuition")
public class TuitionController {

    @Autowired
    private ITuitionService tuitionService;

    /**
     * 提供一个默认不输入后缀,直接可以跳转到具有分页的列表页面
     * @return
     */
/*    @RequestMapping("")
    @PermissionName("缴费视图")
    @RequiresPermissions("tuition:index")
    public String index(){
        return "tuition/list";
    }*/

    /**
     * 具有分页和高级查询
     * @return
     */
    @RequestMapping("list")
    @ResponseBody
    @PermissionName("缴费列表")
    @RequiresPermissions("tuition:list")
    public PageResult list(QueryObject qo){
        PageResult result = tuitionService.query(qo);
        return result;
    }

    /**
     * 查询全部
     * @return
     */
    @RequestMapping("listAll")
    @ResponseBody
    @PermissionName("缴费查询全部")
    @RequiresPermissions("tuition:listAll")
    public List<Tuition> listAll(){
        return tuitionService.selectAll();
    }

    /**
     * 删除
     * @param tuitionId 要删除的学员缴费对象id
     * @return 返回JsonResult对象判断是否操作成功
     */
    @RequestMapping("delete")
    @ResponseBody
    @PermissionName("缴费删除")
    @RequiresPermissions("tuition:delete")
    public JsonResult delete(Long tuitionId){
        JsonResult result = new JsonResult();
        try{
            tuitionService.deleteByPrimaryKey(tuitionId);
        }catch (Exception e){
            e.printStackTrace();
            result.mark("操作失败!");
        }
        return result;
    }

    /**
     *更新
     * @param tuition 要更新的学员缴费对象
     * @return 返回JsonResult对象判断是否操作成功
     */
    @RequestMapping("update")
    @ResponseBody
    @PermissionName("缴费更新")
    @RequiresPermissions("tuition:update")
    public JsonResult update(Tuition tuition){
        JsonResult result = new JsonResult();
        try{
            tuitionService.updateByPrimaryKey(tuition);
        }catch (Exception e){
            e.printStackTrace();
            result.mark("操作失败!");
        }
        return result;
    }

    /**
     * 保存
     * @param tuition 要保存的学员缴费对象
     * @return 返回JsonResult对象判断是否操作成功
     */
    @RequestMapping("save")
    @ResponseBody
    @PermissionName("缴费保存")
    @RequiresPermissions("tuition:save")
    public JsonResult save(Tuition tuition){
        JsonResult result = new JsonResult();
        try{
            tuitionService.insert(tuition);
        }catch (Exception e){
            e.printStackTrace();
            result.mark("操作失败!");
        }
        return result;
    }


    /**
     * 查询未缴费的学员
     *
     * @return
     */
    @RequestMapping("unpaidstudent")
    @ResponseBody
    @PermissionName("查询未缴费对象")
    @RequiresPermissions("tuition:unpaidstudent")
    public List<ProfessionalStuent> unpaidstudent(){
           List<ProfessionalStuent>  list = tuitionService.selectUnpaidstudent();
        return list;
    }

    /**
     * 查询出选中的缴费对象
     *
     * @return
     */
    @RequestMapping("selectTuitionStudentByprofessionStudent")
    @ResponseBody
    @PermissionName("查询已缴费对象")
    @RequiresPermissions("tuition:selectTuitionStudentByprofessionStudent")
    public Tuition selectTuitionStudentByprofessionStudentById(Long professionStudentId){
        Tuition tuition = tuitionService.selectTuitionStudentByprofessionStudentById( professionStudentId);
        return tuition;
    }
}
